//
//  SCCartGoodsListCell.m
//  shangcheng
//
//  Created by 张艳江 on 2019/6/10.
//  Copyright © 2019 张艳江. All rights reserved.
//

#import "SCCartGoodsListCell.h"

@implementation SCCartGoodsListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.goodsImage.contentMode = UIViewContentModeScaleAspectFill;
    self.goodsImage.clipsToBounds = YES;
    
    self.numBgView.layer.borderColor = RGB(239, 239, 239).CGColor;
    self.numBgView.layer.borderWidth = 0.5;
    self.numBgView.layer.cornerRadius = 2.0;
    self.numBgView.clipsToBounds = YES;
}
- (void)setModel:(SCModel *)model{
    _model = model;
    
    if (model.gift_id != nil) {
        [self.goodsImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",Goods_ImageURL,model.gift_image]] placeholderImage:[UIImage imageNamed:@""]];
        self.goodsNameLab.text = model.gift_name;
        self.goodsPriceLab.text = [NSString stringWithFormat:@"%@福豆",[MyTool removeFloatAllZeroByString:model.gift_fen]];
        self.specsLab.text = model.specification;
        self.numLab.text = [NSString stringWithFormat:@"%d",model.gift_num];
    }else{
        [self.goodsImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",Goods_ImageURL,model.wap_pic]] placeholderImage:[UIImage imageNamed:@""]];
        self.goodsNameLab.text = model.goods_name;
        self.goodsPriceLab.text = [NSString stringWithFormat:@"¥%@",[MyTool removeFloatAllZeroByString:model.goods_price]];
        self.specsLab.text = model.spec;
        self.numLab.text = [NSString stringWithFormat:@"%d",model.count];
    }
    
    if (model.cellSelectState == 0) {
        [self.selectBtn setImage:[UIImage imageNamed:@"radio_y_n"] forState:0];
    }else{
        [self.selectBtn setImage:[UIImage imageNamed:@"radio_y_s"] forState:0];
    }
}
- (IBAction)clickBtns:(UIButton *)sender {
    
    if (sender.tag == 10) {//商品选择
        if (self.model.cellSelectState == 0) {
            self.model.cellSelectState = 1;
            [self.selectBtn setImage:[UIImage imageNamed:@"radio_y_s"] forState:UIControlStateNormal];
        }else{
            self.model.cellSelectState = 0;
            [self.selectBtn setImage:[UIImage imageNamed:@"radio_y_n"] forState:UIControlStateNormal];
        }
    }else if (sender.tag == 11){//加法
        if (self.model.gift_id != nil) {
            self.model.gift_num++;
        }else{
            self.model.count++;
        }
    }else if (sender.tag == 12){//减法
        if (self.model.gift_id != nil) {
            if (self.model.gift_num>1) {
                self.model.gift_num--;
            }else{
                [SVProgressHUD showImage:nil status:@"已减至最少购买数量"];
                return;
            }
        }else{
            if (self.model.count>1) {
                self.model.count--;
            }else{
                [SVProgressHUD showImage:nil status:@"已减至最少购买数量"];
                return;
            }
        }
    }
    //代理
    [self.delegate clickCartCellButton:self.model tag:sender.tag];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
